﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

namespace GravityBallScreenSaver.Bodies
{
    public class Ball
    {
        public const uint TAIL_LENGTH = 256;

        /// <summary>
        /// Mass of unit
        /// </summary>
        public long mass { get; set; }
        /// <summary>
        /// Current position in X direction
        /// </summary>
        public float Px0 { get; set; }
        /// <summary>
        /// Current position in Y direction
        /// </summary>
        public float Py0 { get; set; }

        /// <summary>
        /// Current velocity in X direction
        /// </summary>
        public float Vx0 { get; set; }
        /// <summary>
        /// Current velocity in Y direction
        /// </summary>
        public float Vy0 { get; set; }

        /// <summary>
        /// Bounce factor
        /// </summary>
        public float elasticity { get; set; }

        /// <summary>
        /// History of positions
        /// </summary>
        public float[] Px { get; set; }
        /// <summary>
        /// History of positions
        /// </summary>
        public float[] Py { get; set; }

        /// <summary>
        /// Hisotry of absolute velocity
        /// </summary>
        public float[] V { get; set; }
        /// <summary>
        /// History of velocity
        /// </summary>
        public float[] Vx { get; set; }
        /// <summary>
        /// History of velocity
        /// </summary>
        public float[] Vy { get; set; }

        /// <summary>
        /// History of absolute accelleration
        /// </summary>
        public float[] A { get; set; }
        /// <summary>
        /// History of accelleration
        /// </summary>
        public float[] Ax { get; set; }
        /// <summary>
        /// History of accelleration
        /// </summary>
        public float[] Ay { get; set; }

        /// <summary>
        /// History of base colors
        /// </summary>
        public Color[] color { get; set; }
        /// <summary>
        /// Base color
        /// </summary>
        public Color baseColor { get; set; }

        public Ball()
        {
            this.Px = new float[TAIL_LENGTH];
            this.Py = new float[TAIL_LENGTH];

            this.V = new float[TAIL_LENGTH];
            this.Vx = new float[TAIL_LENGTH];
            this.Vy = new float[TAIL_LENGTH];

            this.A = new float[TAIL_LENGTH];
            this.Ax = new float[TAIL_LENGTH];
            this.Ay = new float[TAIL_LENGTH];
           
            this.color = new Color[TAIL_LENGTH];
        }

        public Ball(int width, int height) : this()
        {
            this.mass = Random.GetRandom((int)Properties.Settings.Default.MassMin, (int)Properties.Settings.Default.MassMax);
            this.Px0 = Random.GetRandom((int)Properties.Settings.Default.PlanetDiameter, width-(int)Properties.Settings.Default.PlanetDiameter);
            this.Py0 = Random.GetRandom((int)Properties.Settings.Default.PlanetDiameter, height - (int)Properties.Settings.Default.PlanetDiameter);
            this.Vx0 = Random.GetRandom(-1f * (float)Properties.Settings.Default.Speed, (float)Properties.Settings.Default.Speed);
            this.Vy0 = Random.GetRandom(-1f * (float)Properties.Settings.Default.Speed, (float)Properties.Settings.Default.Speed);
            this.elasticity = Random.GetRandom((float)Properties.Settings.Default.ElastMin, (float)Properties.Settings.Default.ElastMax);           
        }
    }
}